package com.shinewind.info.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shinewind.info.mapper.IModelFirmContentMapper;
import com.shinewind.info.service.IModelFirmContentService;
import com.shinewind.pojo.entity.ModelFirmContent;
import com.shinewind.pojo.vo.ModelFirmContentVo;
import com.shinewind.pojo.vo.ModelFirmsVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ModelFirmContentServiceImpl extends ServiceImpl<IModelFirmContentMapper, ModelFirmContent> implements IModelFirmContentService {
    @Override
    public List<String> getSortTitleByTypeId(Long typeId) {
        List<ModelFirmContent> modelFirmContents = this.lambdaQuery().eq(ModelFirmContent::getTypeId,typeId).list();
        List<String> sortTitles = modelFirmContents.stream().map(sortTitle ->{
            return sortTitle.getCountry();
        }).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());
        System.out.println("sortTitle:"+sortTitles);
        return sortTitles;
    }

    @Override
    public List<ModelFirmsVo> getFirmsContentList(Long typeId, List<String> sortTitle) {
        List<ModelFirmsVo> modelFirmsVos = sortTitle.stream().map(country ->{
            ModelFirmsVo modelFirmsVo = ModelFirmsVo.builder().build();
            modelFirmsVo.setSortTitle(country);
            List<ModelFirmContent> modelFirmContents = this.lambdaQuery().eq(ModelFirmContent::getTypeId,typeId)
                                                        .eq(ModelFirmContent::getCountry,country).list();
            List<ModelFirmContentVo> modelFirmContentVos = modelFirmContents.stream().map(modelFirmContent -> {
                ModelFirmContentVo modelFirmContentVo = ModelFirmContentVo.builder().build();
                BeanUtils.copyProperties(modelFirmContent,modelFirmContentVo);
                return modelFirmContentVo;
            }).collect(Collectors.toList());
            modelFirmsVo.setFirmsContent(modelFirmContentVos);
            return modelFirmsVo;
        }).collect(Collectors.toList());
        return modelFirmsVos;
    }
}